package cn.edu.bupt.scidata.service;

import cn.edu.bupt.scidata.mapper.DateValueMapper;
import cn.edu.bupt.scidata.model.paper.DateValue;
import cn.edu.bupt.scidata.model.paper.Keyword;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;

@Slf4j
@Service
public class AsyncTaskService {
    @Autowired
    private DateValueMapper dateValueMapper;
    @Async
    public Future< List<DateValue>> subByAsync(Keyword keyword, List<Integer> paperIdList, int id1, int id2, String lang) throws Exception {
        List<DateValue> dateValues;
        if (Objects.equals(lang, "EN")) {
            dateValues = dateValueMapper.enKeyTimesort(id1, id2, keyword.getId(), paperIdList);

        } else {
            dateValues = dateValueMapper.KeyTimesort(id1, id2, keyword.getId(), paperIdList);

        }

        return new AsyncResult<>(dateValues);
    }
    @Async
    public Future< List<Keyword>> topic(Integer subid, Integer c_id, String lang) throws Exception {
        List<Keyword> keywords;
        if (lang.equals("EN")) {
            keywords = dateValueMapper.enkeylistlimt3(subid, c_id);
        } else {
            keywords = dateValueMapper.keylistlimt3(subid, c_id);
        }
        return new AsyncResult<>(keywords);
    }

}
